package cn.itlaobing.model;

import java.io.Serializable;
import java.util.List;

/**
 * 分页信息的封装
 */
public class Pagination<T> implements Serializable{
    //包含的数据内容
    private List<T> elements;
    private Integer total;//总条数
    private Integer size;//页大小
    private Integer index;//页码 从1开始

    public List<T> getElements() {
        return elements;
    }

    public void setElements(List<T> elements) {
        this.elements = elements;
    }

    public Integer getTotal() {
        return total;
    }

    public void setTotal(Integer total) {
        this.total = total;
    }

    public Integer getSize() {
        return size;
    }

    public void setSize(Integer size) {
        this.size = size;
    }

    public Integer getIndex() {
        return index;
    }

    public void setIndex(Integer index) {
        this.index = index;
    }

    /**
     * 有没有上一页
     * @return
     */
    public boolean isHasPrevious(){
        return index>1;
    }

    /**
     * 获取上一页页码
     * @return
     */
    public Integer getPrevious(){
        if(isHasPrevious()){
            return index-1;
        }
        return 1;
    }

    /**
     * 有没有下一页
     * @return
     */
    public boolean isHasNext(){
        return index<getTotalPage();
    }

    /**
     * 获取下一页页码
     * @return
     */
    public Integer getNext(){
        if(isHasNext()){
            return index+1;
        }
        return getTotalPage();
    }


    /**
     * 总页数
     * @return
     */
    public Integer getTotalPage(){
      return   total%size==0?total/size:total/size+1;
    }
}
